#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tpi;
typedef tuple<int,int,int,int> rec;
namespace geo{
  struct Line{
    int l,r,h,s;
    bool operator <(const Line &x)const{
      return h<x.h;
    }
  };
  class atlantis{
    private:
      int n;
      vector<Line> L;
      vector<pii> B;
      vector<int> X,C,S;
      inline void build(int u,int l,int r){
        B[u]=make_pair(l,r);
        if(l==r)return;
        int m=l+r>>1;
        build(u<<1,l,m),build(u<<1|1,m+1,r);
        pushup(u);
      };
      inline void pushup(int u){
        if(C[u])S[u]=X[B[u].second+1]-X[B[u].first];
        else S[u]=S[u<<1]+S[u<<1|1];
      }
      inline void update(int u,int l,int r,int c){
        if(X[B[u].second+1]<=l||r<=X[B[u].first])return;
        if(l<=X[B[u].first]&&X[B[u].second+1]<=r)C[u]+=c;
        else update(u<<1,l,r,c),update(u<<1|1,l,r,c);
        pushup(u);
      }
      inline int all_prod(){return S[1];}
    public:
      ll areas_union(vector<rec> a){
        X.resize(a.size()<<1),L.resize(a.size()<<1);
        for(int i=0;i<a.size();i++){
          int xa,ya,xb,yb; tie(xa,ya,xb,yb)=a[i];
          X[i<<1]=xa,X[i<<1|1]=xb;
          L[i<<1]=(Line){xa,xb,ya,1},L[i<<1|1]=(Line){xa,xb,yb,-1};
        }
        sort(L.begin(),L.end());
        sort(X.begin(),X.end()),n=unique(X.begin(),X.end())-X.begin();
        B.resize(n<<2),C.resize(n<<2),S.resize(n<<3),build(1,0,n-2);
        ll c=0;
        for(int i=0;i+1<a.size()<<1;i++){
          update(1,L[i].l,L[i].r,L[i].s);
          c+=1ll*all_prod()*(L[i+1].h-L[i].h);
        }
        return c;
      }
  };
  class atlantis_line{
    private:
      int n;
      vector<Line> L;
      vector<pii> B;
      vector<int> X,C,S;
      inline void build(int u,int l,int r){
        B[u]=make_pair(l,r);
        if(l==r)return;
        int m=l+r>>1;
        build(u<<1,l,m),build(u<<1|1,m+1,r);
        pushup(u);
      };
      inline void pushup(int u){
        if(C[u])S[u]=X[B[u].second+1]-X[B[u].first];
        else S[u]=S[u<<1]+S[u<<1|1];
      }
      inline void update(int u,int l,int r,int c){
        if(X[B[u].second+1]<=l||r<=X[B[u].first])return;
        if(l<=X[B[u].first]&&X[B[u].second+1]<=r)C[u]+=c;
        else update(u<<1,l,r,c),update(u<<1|1,l,r,c);
        pushup(u);
      }
      inline int all_prod(){return S[1];}
    public:
      inline void init(vector<rec> a){
        X.resize(a.size()<<1),L.resize(a.size());
        for(int i=0;i<a.size();i++){
          int xa,ya,xb,yb; tie(xa,ya,xb,yb)=a[i];
          X[i<<1]=xa,X[i<<1|1]=xb,L[i]=(Line){xa,xb,ya,1};
        }
        sort(X.begin(),X.end()),n=unique(X.begin(),X.end())-X.begin();
        B.resize(n<<2),C.resize(n<<2),S.resize(n<<3),build(1,0,n-2);
      }
      inline void add(int p){
        update(1,L[p].l,L[p].r,1);
      }
      inline void del(int p){
        update(1,L[p].l,L[p].r,-1);
      }
      inline int query(){
        return all_prod();
      }
  };
}
int main(){
  freopen("dierti.in","r",stdin);
  freopen("dierti.out","w",stdout);
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int id,n,q; cin>>id>>n>>q;
  vector<rec> a(n);
  for(auto &i:a)cin>>get<0>(i)>>get<1>(i)>>get<2>(i)>>get<3>(i);
  if(id<=6){
    while(q--){
      int l,r; cin>>l>>r;
      cout<<geo::atlantis().areas_union(vector<rec>(a.begin()+l-1,a.begin()+r))<<'\n';
    }
  }
  else if(id<=9){
    for(auto &i:a)swap(get<0>(i),get<1>(i)),swap(get<2>(i),get<3>(i));
    geo::atlantis_line S; S.init(a);
    vector<tpi> Q(q);
    for(int i=0;i<q;i++)
      cin>>get<0>(Q[i])>>get<1>(Q[i]),get<0>(Q[i])--,get<1>(Q[i])--,get<2>(Q[i])=i;
    int sq=sqrt(n),L=0,R=-1;
    sort(Q.begin(),Q.end(),[&](tpi x,tpi y)->bool{
      if(get<0>(x)/sq!=get<0>(y)/sq)return get<0>(x)/sq<get<0>(y)/sq;
      return (get<1>(x)<get<1>(y))^get<0>(x)/sq&1;
    });
    vector<int> w(q);
    for(auto i:Q){
      int l,r,x; tie(l,r,x)=i;
      while(L>l)S.add(--L);
      while(R<r)S.add(++R);
      while(L<l)S.del(L++);
      while(R>r)S.del(R--);
      w[x]=S.query();
    }
    for(int i:w)cout<<i<<'\n';
  }
  return 0;
}